# -*- coding: utf-8 -*-
'''
@author: thomas
'''
from tkinter import *
from tkinter.ttk import *


class StatusBar(Frame):
    """parts: weight list for each part"""
    def __init__(self, master, parts=None):
        Frame.__init__(self, master)
        parts = parts or [1]
        
        self._statusmsg=[StringVar() for p in parts]
        for i,p in enumerate(parts):
            label = Label(self,
                          textvariable=self._statusmsg[i],
                          borderwidth=1, relief=FLAT, anchor=W)
            
            label.grid(row=0,column=i,sticky=W)
            self.columnconfigure(i, weight=p)
    
    def show_status(self,*messages, index=0):
        up=len(self._statusmsg)
        for i, msg in enumerate(messages):
            if i+index >= up: break
            self._statusmsg[i+index].set(msg)
        self.update_idletasks()
    
    def get_statusmsg(self, index=None):
        if index is None: 
            return [s.get() for s in self._statusmsg] 
        return self._statusmsg[index].get()
    
    def clear(self):
        for m in self._statusmsg:
            m.set("")
            
        
